/**
 * Company:wz
 * Title:SecureConvert.java
 * Description:
 * Date:2016年8月5日上午11:19:26
 * author:wei 
 * Version:V1.0
 */

package com.wz.datachannel.util;

/** 
 * 安全转换函数
 * @Description
 * @author wei 
 * @Date 2016年8月5日上午11:19:26
 */
public class SecurityConvert {

	/**
	 * 对象转字符串
	 * @author wei 
	 * @param obj
	 * @param defValue
	 * @return
	 */
	public static String toString(Object obj, String defValue) {
		if(null == obj){
			return defValue;
		}
		try {
			return String.valueOf(obj);
		} catch (Exception e) {
		}

		return defValue;
	}

	public static long toLong(Object obj, long defValue) {
		try {
			return Long.parseLong(obj.toString());
		} catch (Exception e) {
		}

		return defValue;
	}

	public static int toInt(Object obj, int defValue) {
		try {
			return Integer.parseInt(obj.toString());
		} catch (Exception e) {
		}

		return defValue;
	}
}
